package com.ysd.resourceusestatistics.dao;

import java.util.Date;

import com.ysd.resourceusestatistics.model.ConsumeLog;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

/**
 * IConsumeLogDao
 */
public interface IConsumeLogDao extends JpaRepository<ConsumeLog, Integer> {

	// 批量删除
	@Modifying
	@Query(value = "delete from consume_log c where c.id=:id", nativeQuery = true)
	int deleteInBatch(Integer id);
 
		
			//修改
		 
		@Modifying
		@Query("update ConsumeLog c set c.cardNo=:cardNo,c.inTime=:inTime,c.outTime=:outTime,c.readRoomId=:readRoomId where c.id=:id")
			int editCL(@Param("id") Integer id,@Param("cardNo") String cardNo,@Param("inTime") Date inTime,@Param("outTime") Date outTime,@Param("readRoomId") Integer readRoomId);
//查询最后一次进入资源室编号
	@Query(value = "select * from consume_log where in_time = (select max(in_time) from consume_log where card_no = :cardNo)",nativeQuery = true)
	ConsumeLog getLastInTime(String cardNo);

	//更新离开时间
	@Modifying
	@Query(value = "update consume_log c set c.out_time= :outTime where c.id = :id",nativeQuery = true)
	int updateOutTime(Integer id,Date outTime);
}